#include "mytablemodel.h"

MytableModel::MytableModel(QObject *parent)
    : QAbstractTableModel(parent)
{}

QVariant MytableModel::headerData(int section, Qt::Orientation orientation, int role) const
{
    if (role == Qt::DisplayRole) {
        if (orientation == Qt::Horizontal)
        {
            switch (section) {
            case 0:
                return "0";
                break;
            case 1:
                return "1";
                break;
            case 2:
                return "2";
                break;
            case 3:
                return "3";
                break;
            case 4:
                return "4";
                break;
            case 5:
                return "5";
                break;
            default:
                break;
            }
        }
    }
    return QVariant();// FIXME: Implement me!
}

int MytableModel::rowCount(const QModelIndex &parent) const
{
    return m_data.size();
   // FIXME: Implement me!
}

int MytableModel::columnCount(const QModelIndex &parent) const
{
    return 6;
}

//
QVariant MytableModel::data(const QModelIndex &index, int role) const
{
    // if (role == Qt::DisplayRole) {
    //     return QString("Row %1, Col %2").arg(index.row()).arg(index.column());
    // }
    stFileInfo* fileinfo = m_data.at(index.row());
    if (role == Qt::DisplayRole)
    {
       if(index.column() == 0)
       {
            return "1";
       }
       else if(index.column() == 1)
       {
            return "桌面";
       }
       else if(index.column() == 2)
       {
            return "我";
       }
       else if(index.column() == 3)
       {
            return "3";
       }
       else if(index.column() == 4)
       {
            return "4";
       }
       else if(index.column() == 5)
       {
            return "5";
       }
    }

    if (role == Qt::CheckStateRole && index.column() == 0)
    {
        return fileinfo->m_bChecked;
    }

    // FIXME: Implement me!
    return QVariant();
}

bool MytableModel::setdata(const QModelIndex &index, const QVariant &value, int role)
{
    if(role == Qt::CheckStateRole)
    {
        stFileInfo* info = m_data[index.row()];
        info->m_bChecked = value.toBool();
        emit dataChanged(index, index, {role});
    }



    return true;
}

bool MytableModel::insertRows(int row, int count, const QModelIndex &parent)
{
    beginInsertRows(parent, row, row + count - 1);
    // FIXME: Implement me!
    endInsertRows();
    return true;
}

bool MytableModel::insertColumns(int column, int count, const QModelIndex &parent)
{
    beginInsertColumns(parent, column, column + count - 1);
    // FIXME: Implement me!
    endInsertColumns();
    return true;
}

bool MytableModel::removeRows(int row, int count, const QModelIndex &parent)
{
    beginRemoveRows(parent, row, row + count - 1);
    // FIXME: Implement me!
    endRemoveRows();
    return true;
}

bool MytableModel::removeColumns(int column, int count, const QModelIndex &parent)
{
    beginRemoveColumns(parent, column, column + count - 1);
    // FIXME: Implement me!
    endRemoveColumns();
    return true;
}

void MytableModel::addData(stFileInfo* fileinfo)
{
    m_data.append(fileinfo);
}
